
import { createI18n, LocaleMessageArray } from 'vue-i18n' // import from runtime only

import { getVauleByKey } from '@/utils/cookies'

import elementEnLocale from 'element-plus/lib/locale/lang/en'
import elementZhLocale from 'element-plus/lib/locale/lang/zh-cn'
import enLocale from './en'
import zhLocale from './zh-cn'

const messages = {
    en: {
      ...enLocale,
      ...elementEnLocale
    },
    'zh-cn': {
      ...zhLocale,
      ...elementZhLocale
    }
  }
  



export const getLocale = () => {
    const cookieLanguage = getVauleByKey("langeuage")
    if (cookieLanguage) {
        return cookieLanguage
    }
    const language = navigator.language.toLowerCase()
    const locales = Object.keys(messages)
    for (const locale of locales) {
        if (language.indexOf(locale) > -1) {
            return locale
        }
    }
    // Default language is english
    return 'zh'
}



const i18n = createI18n({
    legacy: false,
    locale: getLocale(),
    messages: messages
})

export default i18n
